home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 11.8 KB | 391 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SndPart.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Lonnie Millett
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef SNDPART_H
- #include "SndPart.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWMEMMGR_H
- #include <FWMemMgr.h>
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _STORAGEU_
- #include <StorageU.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _WINSTAT_
- #include <WinStat.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <Quickdraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
- #include <Sound.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SOUNDINPUT__)
- #include <SoundInput.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__OSUTILS__)
- #include <OSUtils.h>
- #endif
-
- #pragma segment sndpart
-
- //==============================================================================
- // •• class CSndPart
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • CSndPart::CSndPart
- //------------------------------------------------------------------------------
-
- CSndPart::CSndPart()
- {
- fSoundHandle = NULL;
- }
-
- //------------------------------------------------------------------------------
- // • CSndPart::~CSndPart
- //------------------------------------------------------------------------------
-
- CSndPart::~CSndPart()
- {
- if (fSoundHandle)
- FW_CMemoryManager::FreeSystemHandle(fSoundHandle);
- }
-
- //------------------------------------------------------------------------------
- // • CSndPart::SetSoundHandle
- //------------------------------------------------------------------------------
-
- void CSndPart::SetSoundHandle(FW_PlatformHandle soundHandle)
- {
- if (fSoundHandle)
- FW_CMemoryManager::FreeSystemHandle(fSoundHandle);
- fSoundHandle = soundHandle;
- }
-
- //------------------------------------------------------------------------------
- // • CSndPart::CreateControlHandle
- //------------------------------------------------------------------------------
-
- ControlHandle CSndPart::CreateControlHandle(XMPPlatformWindow window, const FW_CRect& controlRect)
- {
- FW_SPlatformRect rect;
- controlRect.AsPlatformRect(rect);
- return ::NewControl(window, &rect, "\pPlay Sound", TRUE, 0, 0, 1, pushButProc, (long)this);
- }
-
- //----------------------------------------------------------------------------------------
- // • CSndPart::GetContentPropertyValueType
- //----------------------------------------------------------------------------------------
-
- XMPValueType CSndPart::GetContentPropertyValueType() const
- {
- return kSampleSndKind;
- }
-
- //------------------------------------------------------------------------------
- // • CSndPart::NewFrame
- //------------------------------------------------------------------------------
-
- FW_CFrame* CSndPart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
- {
- FW_UNUSED(presentation);
-
- CSndFrame *frame = new CSndFrame;
- frame->InitSndFrame(xmpFrame, this);
- return frame;
- }
-
- //----------------------------------------------------------------------------------------
- // CSndPart::NewSelection
- //----------------------------------------------------------------------------------------
- FW_CSelection* CSndPart::NewSelection()
- {
- CSndSelection* sndSelection = new CSndSelection;
- sndSelection->InitSndSelection(this);
- return sndSelection;
- }
-
- //------------------------------------------------------------------------------
- // CSndPart::InternalizeContent
- //------------------------------------------------------------------------------
- void CSndPart::InternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
-
- unsigned long sndSize = storageUnit->GetSize();
- if (sndSize != 0)
- {
- FW_PlatformHandle soundHandle = FW_CMemoryManager::AllocateSystemHandle(sndSize);
-
- FW_CMemoryManager::LockSystemHandle(soundHandle);
- storageUnit->GetValue(sndSize, (XMPValue)*soundHandle);
- FW_CMemoryManager::UnlockSystemHandle(soundHandle);
- this->SetSoundHandle(soundHandle);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CSndPart::ExternalizeContent
- //----------------------------------------------------------------------------------------
- void CSndPart::ExternalizeContent(XMPStorageUnit* storageUnit)
- {
- if (fSoundHandle != NULL)
- {
- FW_CMemoryManager::LockSystemHandle(fSoundHandle);
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
- storageUnit->DeleteValue(storageUnit->GetSize());
- storageUnit->SetValue(FW_CMemoryManager::GetSystemHandleSize(fSoundHandle), (XMPValue)*fSoundHandle);
- FW_CMemoryManager::UnlockSystemHandle(fSoundHandle);
- }
- }
-
- //------------------------------------------------------------------------------
- // CSndPart::DoClick
- //------------------------------------------------------------------------------
-
- void CSndPart::DoClick(const FW_CPoint& where, XMPEventData event)
- {
- FW_UNUSED(where);
- FW_UNUSED(event);
-
- if (TestOptionKey(event))
- {
- FW_PlatformHandle soundHandle = NULL;
- FW_SPlatformRect soundBox;
- FW_SPlatformPoint corner;
-
- ::SetRect(&soundBox, 0, 0, 304, 98); // Size of the sound recorder dialog
- ::CenterRectOnScreen(soundBox, TRUE, TRUE, TRUE);
- ::SetPt(&corner, soundBox.left, soundBox.top);
-
- this->GetSession()->GetWindowState()->DeactivateFrontWindows();
- ::SndRecord(NULL, corner, siGoodQuality, &soundHandle);
- this->GetSession()->GetWindowState()->ActivateFrontWindows();
-
- if (soundHandle)
- this->SetSoundHandle(soundHandle);
- }
- else if (fSoundHandle != NULL)
- {
- FW_CMemoryManager::LockSystemHandle(fSoundHandle);
- SndPlay(NULL, fSoundHandle, TRUE);
- FW_CMemoryManager::UnlockSystemHandle(fSoundHandle);
- }
- else
- SysBeep(10);
- }
-
- //==============================================================================
- // •• class CSndFrame
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • CSndFrame::CSndFrame
- //------------------------------------------------------------------------------
-
- CSndFrame::CSndFrame()
- {
- }
-
- //------------------------------------------------------------------------------
- // • CSndFrame::InitSndFrame
- //------------------------------------------------------------------------------
-
- void CSndFrame::InitSndFrame(XMPFrame* frame, FW_CPart* part)
- {
- InitCtlMgrFrame(frame, part);
-
- this->SetDroppable(TRUE);
- }
-
- //------------------------------------------------------------------------------
- // • CSndFrame::~CSndFrame
- //------------------------------------------------------------------------------
-
- CSndFrame::~CSndFrame()
- {
- }
-
- //------------------------------------------------------------------------------
- // • CSndFrame::UpdateUsedShape
- //------------------------------------------------------------------------------
-
- void CSndFrame::UpdateUsedShape()
- {
- FW_CPoint controlSize;
- ((CSndPart*)GetPart())->GetControlSize(controlSize);
- FW_SPlatformRect controlRect;
- ::SetRect(&controlRect, 0, 0, FixedToInt(controlSize.x), FixedToInt(controlSize.y));
-
- FW_PlatformRegion rgn = ::NewRgn();
- ::InsetRect(&controlRect, -1, -1);
- ::OpenRgn();
- ::FrameRoundRect(&controlRect, 16, 16);
- ::CloseRgn(rgn);
-
- XMPShape* scratch = ::NewXMPShape(rgn);
- scratch->Intersect(GetXMPFrame()->GetFrameShape());
- GetXMPFrame()->ChangeUsedShape(scratch);
- }
-
- //==============================================================================
- // •• class CSndSelection
- //==============================================================================
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::CSndSelection
- //---------------------------------------------------------------------------------------
-
- CSndSelection::CSndSelection()
- {
- fSndPart = NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::InitMovieSelection
- //---------------------------------------------------------------------------------------
-
- void CSndSelection::InitSndSelection(CSndPart* sndPart)
- {
- InitSelection(sndPart, FALSE, FALSE);
-
- fSndPart = sndPart;
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::~CSndSelection
- //---------------------------------------------------------------------------------------
-
- CSndSelection::~CSndSelection()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::CloseSelection
- //---------------------------------------------------------------------------------------
-
- void CSndSelection::CloseSelection()
- {
- // Nothing to do here
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::DoClear
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CSndSelection::DoClear()
- {
- // Nothing to do here
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::SelectAll
- //---------------------------------------------------------------------------------------
-
- void CSndSelection::SelectAll()
- {
- // Nothing to do here
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::IsEmpty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CSndSelection::IsEmpty() const
- {
- return FALSE; // We always have something to copy
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::ExternalizeSelection
- //---------------------------------------------------------------------------------------
-
- void CSndSelection::ExternalizeSelection(XMPStorageUnit* storageUnit, FW_CFrame* commandFrame, XMPCloneKind cloneKind)
- {
- FW_UNUSED(commandFrame);
- FW_UNUSED(cloneKind);
-
- // Our content type is the standard 'snd ' type
- storageUnit->AddProperty(kXMPPropContents)->AddValue(fSndPart->GetContentPropertyValueType());
- FW_PlatformHandle soundHandle = fSndPart->GetSoundHandle();
- FW_CMemoryManager::LockSystemHandle(soundHandle);
- storageUnit->SetValue(FW_CMemoryManager::GetSystemHandleSize(soundHandle), (XMPValue)*soundHandle);
- FW_CMemoryManager::UnlockSystemHandle(soundHandle);
- }
-
- //---------------------------------------------------------------------------------------
- // • CSndSelection::InternalizeSelection
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CSndSelection::InternalizeSelection(XMPStorageUnit* storageUnit, XMPCloneKind cloneKind)
- {
- FW_UNUSED(cloneKind);
-
- FW_Boolean internalized = FALSE;
-
- if (storageUnit->Exists(kXMPPropContents, fSndPart->GetContentPropertyValueType(), 0))
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, fSndPart->GetContentPropertyValueType(), 0, kXMPPosUndefined);
-
- unsigned long sndSize = storageUnit->GetSize();
- FW_PlatformHandle soundHandle = FW_CMemoryManager::AllocateSystemHandle(sndSize);
-
- FW_CMemoryManager::LockSystemHandle(soundHandle);
- storageUnit->GetValue(sndSize, (XMPValue)*soundHandle);
- FW_CMemoryManager::UnlockSystemHandle(soundHandle);
- fSndPart->SetSoundHandle(soundHandle);
-
- internalized = TRUE;
- }
-
- return internalized;
- }
-
-